package com.ftg.learn.chapter12;

import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;

/**
 * 事爹 : QA
 * 一对多  多的设计
 * @author kangjx
 * @createTime 2022/8/1
 */
public class Clazz {

    /**
     * 构造方法
     */
    public Clazz(int stuCapacity){
        this.stus = new Student[stuCapacity];
    }

    public Clazz(Integer cno,String cname,String address,int stuCapacity){
        this.cno = cno;
        this.cname = cname;
        this.address = address;
        this.stus = new Student[stuCapacity];
    }

    private int index = 0;

    private Integer cno;

    private String cname;

    private String address;

    public Integer getCno() {
        return cno;
    }

    public void setCno(Integer cno) {
        this.cno = cno;
    }

    public String getCname() {
        return cname;
    }

    public void setCname(String cname) {
        this.cname = cname;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * 数组 多个
     */
    private Student[] stus;

    /**
     * 一次多个学生
     * @param stu
     */
    public void add(Student... stu){
        if(stu != null){
          for(Student s : stu){
              add(s);
          }
        }
    }

    /**
     * 一次添加一个学生
     * @param stu
     */
    public String add(Student stu){
        if(index < this.stus.length){
            this.stus[index++] = stu;
            return "学生添加成功";
        }
        return "学生添加失败";
    }

    /**
     * 表示现在班级里面有几个学生
     * @return
     */
    public int getStudentSize(){
        return this.index;
    }

    public Student[] currentStudent(){
        return Arrays.copyOf(this.stus,index);
    }

    public int maxStudentSize(){
        return this.stus.length;
    }

    public static void main(String[] args) {
        //基本信息
        Student stu = new Student();
        stu.setSno(1);
        stu.setSname("张二狗");
        stu.setSage(13);
        Clazz clz = new Clazz(1001,"软一","松北",23);
        clz.add(stu);
        stu.setC1(clz);

        Student stu1 = new Student();
        stu1.setSno(1);
        stu1.setSname("王春花");
        stu1.setSage(13);

        clz.add(stu1);
        stu1.setC1(clz);

        System.out.println(stu.getC1().getCname());
//        stu 张二狗
        Student[] stus = stu.getC1().currentStudent();
        for (int i = 0; i < stus.length; i++) {
            System.out.println(stus[i].getSname());
        }
    }

}
